package cn.tedu.rabbitmqboot.m4;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Scanner;

@Component
public class Producer {
    @Autowired
    private AmqpTemplate amqpTemplate;
    public void send(){
        while (true){
            System.out.println("输入消息:");
            String msg = new Scanner(System.in).nextLine();
            System.out.println("输入路由键:");
            String key = new Scanner(System.in).nextLine();
            //默认是持久消息,第二个参数对于fanout交换机无效
            amqpTemplate.convertAndSend("direct_logs",key,msg);
        }
    }

}
